home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / addelbnd.fr_ / addelbnd.fr
Text File  |  1995-07-04  |  9KB  |  281 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Bound Updater"
  5.    ClientHeight    =   3345
  6.    ClientLeft      =   1950
  7.    ClientTop       =   2055
  8.    ClientWidth     =   6420
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   4035
  19.    Left            =   1890
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   3345
  22.    ScaleWidth      =   6420
  23.    Top             =   1425
  24.    Width           =   6540
  25.    Begin VB.TextBox txtPublisherID 
  26.       DataField       =   "PubID"
  27.       DataSource      =   "dtaTitles"
  28.       Height          =   315
  29.       Left            =   1860
  30.       TabIndex        =   6
  31.       Top             =   1860
  32.       Width           =   855
  33.    End
  34.    Begin VB.TextBox txtISBN 
  35.       DataField       =   "ISBN"
  36.       DataSource      =   "dtaTitles"
  37.       Height          =   315
  38.       Left            =   1860
  39.       MaxLength       =   13
  40.       TabIndex        =   2
  41.       Top             =   1380
  42.       Width           =   1635
  43.    End
  44.    Begin VB.TextBox txtYearPublished 
  45.       DataField       =   "Year Published"
  46.       DataSource      =   "dtaTitles"
  47.       Height          =   285
  48.       Left            =   1860
  49.       TabIndex        =   1
  50.       Top             =   900
  51.       Width           =   735
  52.    End
  53.    Begin VB.TextBox txtTitle 
  54.       DataField       =   "Title"
  55.       DataSource      =   "dtaTitles"
  56.       Height          =   555
  57.       Left            =   1860
  58.       MultiLine       =   -1  'True
  59.       TabIndex        =   0
  60.       Top             =   180
  61.       Width           =   4095
  62.    End
  63.    Begin VB.Data dtaTitles 
  64.       Caption         =   "Titles"
  65.       Connect         =   "Access"
  66.       DatabaseName    =   "C:\VB\BIBLIO.MDB"
  67.       EOFAction       =   2  'Add New
  68.       Exclusive       =   0   'False
  69.       Height          =   300
  70.       Left            =   660
  71.       Options         =   0
  72.       ReadOnly        =   0   'False
  73.       RecordsetType   =   1  'Dynaset
  74.       RecordSource    =   "Titles"
  75.       Top             =   2520
  76.       Width           =   1815
  77.    End
  78.    Begin VB.Label Label4 
  79.       AutoSize        =   -1  'True
  80.       BackColor       =   &H00C0C0C0&
  81.       Caption         =   "Publisher ID:"
  82.       Height          =   195
  83.       Left            =   600
  84.       TabIndex        =   7
  85.       Top             =   1920
  86.       Width           =   1110
  87.    End
  88.    Begin VB.Label Label3 
  89.       AutoSize        =   -1  'True
  90.       BackColor       =   &H00C0C0C0&
  91.       Caption         =   "ISBN:"
  92.       Height          =   195
  93.       Left            =   1200
  94.       TabIndex        =   5
  95.       Top             =   1440
  96.       Width           =   510
  97.    End
  98.    Begin VB.Label Label2 
  99.       AutoSize        =   -1  'True
  100.       BackColor       =   &H00C0C0C0&
  101.       Caption         =   "Year Published:"
  102.       Height          =   195
  103.       Left            =   360
  104.       TabIndex        =   4
  105.       Top             =   960
  106.       Width           =   1350
  107.    End
  108.    Begin VB.Label Label1 
  109.       AutoSize        =   -1  'True
  110.       BackColor       =   &H00C0C0C0&
  111.       Caption         =   "Title:"
  112.       Height          =   195
  113.       Left            =   1200
  114.       TabIndex        =   3
  115.       Top             =   180
  116.       Width           =   450
  117.    End
  118.    Begin VB.Menu mnuFile 
  119.       Caption         =   "&File"
  120.       Begin VB.Menu mnuFileExit 
  121.          Caption         =   "E&xit"
  122.       End
  123.    End
  124.    Begin VB.Menu mnuEdit 
  125.       Caption         =   "&Edit"
  126.       Begin VB.Menu mnuEditUndo 
  127.          Caption         =   "&Undo"
  128.          Shortcut        =   %{BKSP}
  129.       End
  130.    End
  131.    Begin VB.Menu mnuData 
  132.       Caption         =   "&Data"
  133.       Begin VB.Menu mnuDataAddRecord 
  134.          Caption         =   "&Add Record"
  135.       End
  136.       Begin VB.Menu mnuDataDeleteRecord 
  137.          Caption         =   "&Delete Record"
  138.       End
  139.       Begin VB.Menu mnuDataSaveRecord 
  140.          Caption         =   "&Save Record"
  141.       End
  142.    End
  143. End
  144. Attribute VB_Name = "Form1"
  145. Attribute VB_Creatable = False
  146. Attribute VB_Exposed = False
  147. Option Explicit
  148.  
  149. Private UpdateCancelled As Boolean
  150.  
  151. Private Sub dtaTitles_Validate(Action As Integer, Save As Integer)
  152.     Dim msg As String
  153.  
  154.     If Save = True Or Action = vbDataActionUpdate _
  155.         Or dtaTitles.Recordset.EditMode = dbEditAdd _
  156.     Then
  157.     
  158.         ' Either one or more bound controls has changed, or the Update
  159.         ' method was invoked from code, or we're adding a new record.
  160.         ' So verify that all fields have legal entries. If a field has
  161.         ' an incorrect value, set the variable msg to a string explaining
  162.         ' the error and set the focus to that field to facilitate the user's
  163.         ' correcting the error.
  164.         If txtTitle = "" Then
  165.              msg = "You must enter a title."
  166.              txtTitle.SetFocus
  167.         ElseIf txtISBN = "" Then
  168.              msg = "You must enter an ISBN."
  169.              txtISBN.SetFocus
  170.         ElseIf txtYearPublished <> "" And Not IsNumeric(txtYearPublished) Then
  171.             msg = "The Year Published must be numeric."
  172.             txtYearPublished.SetFocus
  173.         ElseIf txtPublisherID = "" Or Not IsNumeric(txtPublisherID) Then
  174.             msg = "You must enter a numeric Publisher ID."
  175.             txtPublisherID.SetFocus
  176.         End If
  177.     End If
  178.     If msg <> "" Then
  179.  
  180.         ' We have something in the variable msg, which means that an error
  181.         ' has occurred. Display the message for the user.
  182.         MsgBox msg, vbExclamation
  183.         
  184.        ' Cancel the Validate event
  185.         Action = vbDataActionCancel
  186.         
  187.         ' Set the form-level variable UpdateCancelled to True. This flags
  188.         ' the Unload event to cancel the unload.
  189.         UpdateCancelled = True
  190.         
  191.     Else
  192.     
  193.         ' No errors, so set the form level variable UpdateCancelled False
  194.         ' to flag the Unload event to go ahead and proceed with the unload.
  195.         UpdateCancelled = False
  196.     End If
  197. End Sub
  198.  
  199. Private Sub mnuEditUndo_Click()
  200.     If dtaTitles.EditMode = dbEditAdd Then
  201.     
  202.         ' The user clicked Undo while adding a new record, so cancel the
  203.         ' AddNew operation.
  204.         dtaTitles.Recordset.CancelUpdate
  205.         
  206.         ' Now make a valid record the current record.
  207.         dtaTitles.Recordset.MoveLast
  208.     Else
  209.     
  210.         ' The user clicked Undo while editing an existing record, so reset
  211.         ' values in the controls to values from the current recordset record.
  212.         dtaTitles.UpdateControls
  213.     End If
  214. End Sub
  215.  
  216. Private Sub mnuFileExit_Click()
  217.    Unload Me
  218. End Sub
  219.  
  220. Private Sub Form_Unload(Cancel As Integer)
  221.  
  222.     If UpdateCancelled Then
  223.         
  224.         ' The Validate event failed, so cancel the unload.
  225.         Cancel = True
  226.         
  227.     ElseIf dtaTitles.Recordset.EditMode = dbEditAdd Then
  228.     
  229.         ' The Validate event succeeded, so write the new record to the
  230.         ' recordset.
  231.         dtaTitles.Recordset.UPDATE
  232.     End If
  233.     
  234. End Sub
  235.  
  236. Private Sub mnuDataSaveRecord_Click()
  237.  
  238.     ' The user clicked SaveRecord, so call the Update method to transfer
  239.     ' the values in the bound controls to their respective fields.
  240.     dtaTitles.Recordset.UPDATE
  241. End Sub
  242.  
  243. Private Sub mnuDataAddRecord_Click()
  244.  
  245.     ' The user clicked Add Record. Reset all controls to the default for a
  246.     ' new record and make space in the copy buffer for a new recpord.
  247.     dtaTitles.Recordset.AddNew
  248.     
  249.     ' The default for Year Published in the database is 0. Change it to
  250.     ' nothing.
  251.     txtYearPublished = ""
  252.     
  253.     
  254.     ' Set the focus to the first control on the form.
  255.     txtTitle.SetFocus
  256. End Sub
  257.  
  258. Private Sub mnuDataDeleteRecord_Click()
  259.     Dim msg As String
  260.  
  261.     ' Verify that the user wants to delete the record.
  262.     msg = "Are you sure you want to delete "
  263.     msg = msg & IIf(txtTitle <> "", txtTitle, "this record") & "?"
  264.     If MsgBox(msg, vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
  265.     
  266.         ' The user wants to delete, so delete the record.
  267.         dtaTitles.Recordset.DELETE
  268.         
  269.         ' Make a valid record the current record.
  270.         dtaTitles.Recordset.MoveNext
  271.         
  272.         ' If we just deleted the last record in the recordset,
  273.         ' position the recordpointer on the new last record.
  274.         If dtaTitles.Recordset.EOF Then dtaTitles.Recordset.MoveLast
  275.     End If
  276. End Sub
  277.  
  278.  
  279.  
  280.  
  281.